<div class="col-xs-12 hide" id='hide_time_form_div'>
    <form class="form-horizontal time_form"  action="{:url('');}"  method="post">
        <div class="m-b-md" style="font-size:1.8rem">
            填写起床时间和入睡时间
            <h5 style="font-size:1.3rem">
                例如,八点半可以填写8.30
            </h5>
        </div>
        <div class="form-group row">
            <label for="date" class="col-xs-3 control-label p-t-xs">开始时间</label>
            <div class="col-xs-6">
                <input name="start_time" type="number" class="form-control" id="start_time" placeholder="" value='0'>
            </div>
        </div>
        <div class="form-group row">
            <label for="date" class="col-xs-3 control-label p-t-xs">结束时间</label>
            <div class="col-xs-6">
                <input name="end_time" type="number" class="form-control" id="end_time" placeholder="" value='0'>
            </div>
        </div>
    </form>
</div>
<div class="col-xs-12 hide" id='hide_content_form_div'>
    <form class="form-horizontal content_form"  action="{:url('');}"  method="post">
        <div class="form-group row">
            <label for="type" class="col-xs-2 control-label p-t-xs p-b-xs p-l-md" style="text-align:left">类型</label>
            <div class="btn-group btn-group-sm col-xs-12 m-l-sm" role="group" aria-label="...">
<!--                <div class="btn-group" role="group">
                    <button type="button" class="btn btn-default type_btn" data-id="1" >娱乐</button>
                </div>
                <div class="btn-group" role="group">
                    <button type="button" class="btn btn-default type_btn" data-id="2" >发呆</button>
                </div>
                <div class="btn-group" role="group">
                    <button type="button" class="btn btn-default type_btn" data-id="3" >日常</button>
                </div>
                <div class="btn-group" role="group">
                    <button type="button" class="btn btn-default type_btn" data-id="4" >有益</button>
                </div>-->
            {volist name="type_map_name" id="vo"}
                    <div class="btn-group" role="group">
                                <button type="button" class="btn btn-default type_btn" data-id="{$key|default=''}" >{$vo|default=''}</button>
                    </div>
            {/volist}
            </div>
                <input name="type" id="type_input" type="hidden" class="form-control"  placeholder="" value='0'>
                <input name="time" id="time_input" type="hidden" class="form-control" placeholder="" value='0'>
                <input name="half_id" id="half_id_input" type="hidden" class="form-control" placeholder="" value=''>
        </div>
        <div class="form-group row">
            <label for="date" class="col-xs-2 control-label p-t-xs p-b-xs  p-l-md" style="text-align:left">内容</label>
            <div class="col-xs-9 m-l-sm">
                <input name="content" type="text" class="form-control" id="content_input" placeholder="" value=''>
            </div>
        </div>
    </form>
</div>
<div class='col-xs-12 m-t-xs p-l-xs p-r-xs'>
    {foreach name="half_list" item="vo" key = "time"}
    <div class="col-xs-12 text-center p-l-zero p-r-zero" style="line-height: 5rem;font-size: 1.5rem;border: 1px solid #e1e1e8;border-radius: 8px;margin-top: 10px;">
        <div class="col-xs-4 p-l-xs p-r-xs" >{$time|default='无'}</div>
        <div  class="col-xs-8 p-l-xs p-r-xs show_contnet_form text-left" style="border-left: 1px solid #e1e1e8" 
             data-time="{$time|default='无'}" data-type="{$vo['type']|default='0'}" data-content="{$vo.content|default=''}" data-id="{$vo.id|default=''}">
            <span class="glyphicon glyphicon-stop m-r-xs" style="color:{$vo['color']|default='white'}" ></span>
            {$vo.content|default=''}
        </div>
    </div>
    {/foreach}
</div> 
<div id="add_div" class="row" style ="position:fixed;bottom: 0px;width:100%;background-color: white" >
    
<!--    <div class="col-xs-2 text-center m-b-xs m-t-xs" style="color: #286090;position: relative">
        <a href="{:merge_url('plan/plan_list');} " class="btn btn-info btn-sm " role="button" > 
           晓计划
        </a>
    </div>-->
    
    <div class="col-xs-12 text-center m-b-xs" style="color: #286090">
        <a href="{:merge_url('half_stats');} " class="btn btn-info btn-lg " role="button" > 
            <span  class="glyphicon glyphicon-stats"></span>&nbsp;统计
        </a>
    </div>
</div>
<script>
    $ (function ($)
    {
        $("body").on('click',".type_btn",function() {
                {volist name="$type_map_color_css" id="vo"}
                    $('.btn-group .btn').removeClass('{$vo}');
                {/volist}
            
            var color_id = $(this).data('id');
            switch(color_id)
            {
                {volist name="$type_map_color_css" id="vo"}
                case {$key}:
                    $(this).addClass('{$vo}');
                    break;
                {/volist}
            }
            $('[name="type"]').val(color_id)
        })
        
        $(".show_contnet_form").on('click',function()
        {
                    var hide_content_form_div = $('#hide_content_form_div').first();
                    var time = $(this).data('time');
                    var type = $(this).data('type');
                    var content = $(this).data('content');
                    var half_id = $(this).data('id');
                    $('[name="time"]').val(time);
                    layer.open({
                            content:hide_content_form_div.html(),
                            btn: '提交',
                            style: 'position:relative;top:-30px',
                            success : function(){
                                       $('[name="half_id"]').val(half_id);
                                       $('[name="type"]').val(type);
                                       $('[name="content"]').val(content);
                                       $('.layui-m-layercont .type_btn').each(function() {
                                                if ($(this).data('id')==type) {
                                                          $(this).click();
                                                }
                                       })
                            },
                            yes: function(){
                                      $('[name="time"]').val(time);
                                      hide_content_form = $('.content_form').last();
                                      console.log(hide_content_form.serializeArray());
                                      $.post('{:merge_url('');}',hide_content_form.serializeArray(),function(res) {
                                          console.log(666);
                                                $('.hide ul').children('li.change_tab').first().click();
//                                            location.reload();
                                      });
                                      layer.closeAll();
                            }
                    });
        });
        
        {if ((empty($user_info->wake_up_time) || empty($user_info->sleep_time)))}
        var hide_time_form_div = $('#hide_time_form_div').first();
        layer.open({
          content:hide_time_form_div.html(),
          btn: '提交',
          yes: function ()
          {
              time_form = $('.time_form').last();
              time_form.submit();
//              console.log(time_form.serializeArray());
//              $.post(time_form.attr('action'),time_form.serializeArray(),function()
//              {
//                  layer.closeAll ();
//              });
          }
        });
        {else /} 
        {/if}
    })

</script>